/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package NLP.PostProcess;

import java.io.File;
import java.util.ArrayList;

/**
 *
 * @author leng
 */
public class ExtractToDocumentViewer {
    private static UserInterface.GUI gui = null;

    public static void setGUI(UserInterface.GUI gui){
        ExtractToDocumentViewer.gui = gui;
    }

    public void ShowOnDocumentViewer(){

        copytoDepot();

        // refresh screen
        //if(gui!=null){
        //    gui.refreshResultEditor();
        //}
    }

    private void assignAndRecordMentionID( String filename, ArrayList _conceptDetailsInArrayList )
    {
            ArrayList modifiedResults = _conceptDetailsInArrayList;
            int size = _conceptDetailsInArrayList.size();



            // compare a entry result to others
            for(int i=0; i<size;i++)
            {
                // *** get current concept result
                NLP.StorageSpaceDraftLevel.Table_Concept cd
                    = (NLP.StorageSpaceDraftLevel.Table_Concept) modifiedResults.get(i);

                ResultEditor.Annotations.Depot depot = new ResultEditor.Annotations.Depot();
                //System.out.println("==  ADDING: to file: [" + filename + "]");
                //System.out.println("            text [" + cd.concept_text + "]" );
                //System.out.println("            text [" + cd.span_start_in_file + ", "+ cd.span_end_in_file +  "]" );
                //System.out.println();

                File f = new File(filename);


                // get the classname
                String classname;
                if(cd.foundclassname){
                    if((cd.classname!=null)&&(cd.classname.trim().length()>0)){
                        classname = cd.classname.trim();
                    }else{
                        classname = "unknown";
                    }
                }else{
                    try{
                        Dictionaries.ConceptDictionaryFormat df
                            = Dictionaries.ConceptDictionaries.ConceptArray.get(cd.found_by_which_dictionary);
                        classname = df.Comment.get(cd.found_by_which_entry);
                    }catch(Exception ex){
                        classname = "unknown";
                    }
                }

                depot.addANewAnnotation(f.getName(), 
                        cd.concept_text,
                        cd.span_start_in_file,
                        cd.span_end_in_file,
                        "date",
                        classname,
                        "Annotator-eHOST",
                        "annotator-id",
                        null,
                        null,
                        cd.uniqueindex);
            }




    }

    private void copytoDepot(){
        // find how many paragraph had been processed
        int number_of_paragraphs = NLP.StorageSpaceDraftLevel.StorageSpace.Length();
        // if no paragraph got processed, exit from this function
        if(number_of_paragraphs <= 0)
            return;

        // **** to all records in the storage space, if they belong to the specific file
        // apply the concept result filter to it
        for(int i=0;i<number_of_paragraphs;i++)
        {
            // get specified record
            NLP.StorageSpaceDraftLevel.DraftLevelFormat cef
                = (NLP.StorageSpaceDraftLevel.DraftLevelFormat)NLP.StorageSpaceDraftLevel.StorageSpace.getParagraphInFormat(i);

            /** [1] assign mention id to concepts*/
            // if information belong to current file
            // apply the concept result filter
            ArrayList conceptsdetails = cef.ConceptDetails;
            // assign id for these concept results
            assignAndRecordMentionID(cef.filename, conceptsdetails);


            /* / update these modified concept results to the paragraph
            // and update the paragraph in the storagespace in draft level
            updateConcepts_into_StorageSpaceDraftLevel(i, modifiedConceptArrayList);

            // [2] assign mention id to SSN

            if(env.Parameters.OUTPUTSSN){
                ArrayList SSNDs = cef.SSNDetails;
                // assign id for these concept results
                ArrayList modifiedSSNArrayList = assignAndRecordMentionID_toSSN(SSNDs);
                updateSSNs_into_StorageSpaceDraftLevel(i, modifiedSSNArrayList );
            }

            // [3] assign mention id to Date and time terms

            if(env.Parameters.OUTPUTDATE){
                ArrayList dates = cef.Dates;
                // assign id for these concept results
                ArrayList modifiedSSNArrayList = assignAndRecordMentionID_toDates(dates);
                updateDates_into_StorageSpaceDraftLevel(i, modifiedSSNArrayList );
            }

            // [4] assign mention id to terms found by filter of
              custom regular expression

            if(env.Parameters.OUTPUTCUSTOMREGEX){
                ArrayList<Table_CustomRegex> customRegexs = cef.CustomRegex;
                // assign id for these concept results
                ArrayList<Table_CustomRegex> modifiedCustomRegexArrayList
                        = assignAndRecordMentionID_toCustomRegexs(customRegexs);
                updateCustomRegexs_into_StorageSpaceDraftLevel(i, modifiedCustomRegexArrayList );
            }

            // [5] assign mention id to negation phrases

            if(env.Parameters.OUTPUTNEGATION){

                ArrayList<Table_Negation> negations = cef.Negations;
                // assign mention id for these negations
                assignMentionID_toNegations(negations);

            }

            // [6] assign mention id to experiencer

            if(env.Parameters.OUTPUTEXPERIENCER){
                ArrayList<Table_Experiencer> experiencer = cef.Experiencer;
                assignMentionID_toExperiencer(experiencer);
            }
            */


        }
    }
}
